home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / basic / order.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  948b  |  48 lines

  1.  
  2. // This programs is using dictionaries with keys of type "string" with two 
  3. // different linear orders, the lexicographic ordering  (default ordering)
  4. // and the reversed lexicographic ordering 
  5.  
  6.  
  7. #include <LEDA/dictionary.h>
  8.  
  9. int cmp_rev(const string& x, const string& y) { return compare(y,x); }
  10.  
  11. int cmp_length(const string& x, const string& y) 
  12. { return compare(x.length(),y.length()); }
  13.  
  14. DEFINE_LINEAR_ORDER(string,cmp_rev,string_r)
  15. DEFINE_LINEAR_ORDER(string,cmp_length,string_l)
  16.  
  17.  
  18.  
  19.  
  20. main()
  21. {
  22.   dictionary<string,int>    D;
  23.   dictionary<string_r,int>  D_rev;
  24.   dictionary<string_l,int>  D_length;
  25.  
  26.   string x;
  27.  
  28.   while (cin >> x) 
  29.   { D.insert(x,0);
  30.     D_rev.insert(x,0);
  31.     D_length.insert(x,0);
  32.    }
  33.  
  34.   dic_item it;
  35.  
  36.   forall_items(it,D) cout << D.key(it)  << "\n";
  37.   newline;
  38.  
  39.   forall_items(it,D_rev) cout << D_rev.key(it)  << "\n";
  40.   newline;
  41.  
  42.   forall_items(it,D_length) cout << D_length.key(it)  << "\n";
  43.   newline;
  44.  
  45.   return 0;
  46. }
  47.  
  48.